เข้าสู่ระบบ สมัครสมาชิก

dynamically scoped การใช้

ประโยคมือถือ
  • Common Lisp has support for dynamically scoped variables, which are also called special variables.
  • Dynamically scoped variables are used to pass things between procedure calls without using the stack.
  • For example, the current input and output streams are stored in dynamically scoped variables.
  • Certain other kinds of bindings are necessarily dynamically scoped also, such as restarts and catch tags.
  • CL supports dynamically scoped variables as well, but they must be explicitly declared as " special ".
  • Because PC-LISP implements Franz LISP, it is a dynamically scoped predecessor to modern Common Lisp.
  • Binding a dynamically scoped variable temporarily creates a new memory location for that variable, and associates the name with that location.
  • Most of the Lisp systems whose designs contributed to Common Lisp such as ZetaLisp and Franz Lisp used dynamically scoped variables in their interpreters and lexically scoped variables in their compilers.
  • Perl also has a local operator that does not create automatic variables, instead giving global ( package ) variables a temporary value, which is dynamically scoped to the enclosing block.
  • Function bindings cannot be dynamically scoped using flet ( which only provides lexically scoped function bindings ), but function objects ( a first-level object in Common Lisp ) can be assigned to dynamically scoped variables, bound using let in dynamic scope, then called using funcall or APPLY.
  • Function bindings cannot be dynamically scoped using flet ( which only provides lexically scoped function bindings ), but function objects ( a first-level object in Common Lisp ) can be assigned to dynamically scoped variables, bound using let in dynamic scope, then called using funcall or APPLY.
  • The latter may occur implicitly through the use of a construct like DEFVAR or DEFPARAMETER . It is an important convention in Common Lisp programming that special ( i . e . dynamically scoped ) variables have names which begin and end with an asterisk sigil * in what is called the  earmuff convention.
  • Originally, this was intended as an optimization; lexical scoping was still uncommon and of uncertain performance . " I asked RMS when he was implementing emacs lisp why it was dynamically scoped and his exact reply was that lexical scope was too inefficient . " Dynamic scoping was also meant to provide greater flexibility for user customizations.